﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FubiManger.UI;
using DAL;

namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class Adddiskcontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public Adddiskcontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        public string merchantid { get; set; }
        /// <summary>
        /// 1更新
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 编号
        /// </summary>
        public string diskid { get; set; }
        /// <summary>
        /// 餐桌名称
        /// </summary>
        public string diskname { get; set; }
        /// <summary>
        /// 人数
        /// </summary>
        public string diskperson { get; set; }
        private void btnclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnsave_Press(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtdiskname.Text))
            {
                MessageBox.Show("请填写餐桌名称");
            }
            else if (string.IsNullOrEmpty(txtperson.Text))
            {
                MessageBox.Show("请填用可容纳人数");
            }
            else
            {
                if (status == "1")
                {
                    if (diskDal.Updatedisk(diskid, txtdiskname.Text, txtperson.Text) > 0)
                    {
                        //MessageBox.Show("更新成功", (obj, args) =>
                        //{
                        //    ((EditdiskForm)this.Form).Refsh();//刷新
                        //    this.Close();
                        //});
                        ((EditdiskForm)this.Form).Refsh();//刷新
                        this.Close();
                    }
                }
                else
                {
                    if (diskDal.Adddisk(merchantid, txtdiskname.Text, txtperson.Text) > 0)
                    {
                        //MessageBox.Show("添加成功", (obj, args) =>
                        //{
                            
                        //});
                        ((EditdiskForm)this.Form).Refsh();//刷新
                        this.Close();
                    }
                }
            }
        }

        private void Adddiskcontrol_Load(object sender, EventArgs e)
        {
            if (status == "1")
            {
                lbltitiel.Text = "更新餐桌";
                btnsave.Text = "更新";
                txtdiskname.Text = diskname;//餐桌名称
                txtperson.Text = diskperson;//餐桌人数
            }
        }
    }
}